package com.mmz.test.sort;

public class Quick {

	public static void main(String[] args) {
		int[] arr={2,1,2,3,4,2,54,21,45,-12,12,-12,67,2,-34,0};
		//int[] arr={4,5,6,3,2,1};
		int key =arr[0];
		int low = 0;
		int high = arr.length-1;
		sort(low,high,arr);
		for(int i=0;i<arr.length;i++){
			System.out.println(arr[i]);
		}
	}
	
	static void sort(int low,int high,int[] arr){
		int start =low;
		int end = high;
		int inx = (high+low)/2;
		int key =arr[inx];
		while(high>low){
			while(high>low){
				if(arr[high]>=key)
					high--;
				else{
					int temp=arr[low];
					arr[low]=arr[high];
					arr[high]=temp;
					break;
				}	
			}
			while(high>low){
				if(arr[low]<key)
					low++;
				else{
					int temp=arr[low];
					arr[low]=arr[high];
					arr[high]=temp;
					break;
				}	
			}
			
		}
		if(low>start){
			sort(start,low-1,arr);
			
		}
		if(low<end){
			sort(low+1,end,arr);
		}
		
	}

}
